<template>
  <div class="app-container">
    <div class="syl-group">
      <el-form ref="queryForm" :model="queryParams" :inline="true">
        <el-form-item label="选择时间:">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            size="small"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="ordinary" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="equWristbandList" :header-cell-style="{background:'#F3F9FF',color:'#333333',fontWeight: 600}">
        <el-table-column label="内容" align="center" prop="content" :show-overflow-tooltip="true" />
        <el-table-column label="图片" align="center" prop="attachImage">
          <template slot-scope="score">
            <img
              v-for="(item,index) in getImg(score.row.attachImage)"
              :key="index"
              :src="serverMap.baseImg+'/'+item"
              alt=""
              style="max-width: 50px;max-height: 50px;margin-right:6px;cursor: pointer"
              @click="getImgValue(serverMap.baseImg+'/'+item)"
            >
          </template>
        </el-table-column>
        <el-table-column label="渠道" align="center" prop="feedbackChannel">
          <template slot-scope="scope">
            <span v-if="scope.row.feedbackChannel === '1'">企业端</span>
            <span v-if="scope.row.feedbackChannel === '2'">员工端</span>
          </template>
        </el-table-column>
        <el-table-column label="反馈人员/企业" align="center" prop="employeeName" :show-overflow-tooltip="true" />
        <el-table-column label="反馈时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
            >查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 添加或修改门店对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="840px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row :gutter="20">
          <el-col :span="11">
            <el-form-item label="反馈人员/公司:">
              <el-input v-model="form.employeeName" :disabled="true" />
            </el-form-item>
            <el-form-item label="联系方式:">
              <el-input v-model="form.employeePhone" :disabled="true" />
            </el-form-item>
            <el-form-item label="反馈时间:">
              <el-date-picker
                v-model="form.createTime"
                type="date"
                :disabled="true"
                style="width: 100%"
                placeholder="选择日期"
                format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
            <el-form-item label="反馈渠道:">
              <el-input v-model="form.feedbackChannel" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="13">
            <el-form-item label="反馈图片">
              <img
                v-for="(item,index) in getImg(form.attachImage)"
                :key="index"
                :src="serverMap.baseImg+'/'+item"
                alt=""
                style="max-width: 101px;max-height: 101px;margin: 0  8px;cursor: pointer"
                @click="getImgValue(serverMap.baseImg+'/'+item)"
              >
            </el-form-item>
            <el-form-item label="反馈内容">
              <el-input
                v-model="form.content"
                :disabled="true"
                style="width: 260px"
                resize="none"
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 4}"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!--照片弹窗-->
    <el-dialog
      :title="title1"
      :visible.sync="dialogVisible"
      width="400px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div style="width: 100%;text-align: center">
        <img style="max-width: 240px;" :src="dialogImageUrl" alt="">
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getOpinion, getByOpinionId } from '@/api/evaluate/opinion'
import { getCompanyOrderInfo } from '@/api/order'
import serverMap from '../../../../config/serverMap'

export default {
  name: 'Index',
  data() {
    return {
      // 照片回显
      dialogImageUrl: null,
      serverMap: serverMap,
      // 日期
      dateRange: [],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 评价表格数据
      equWristbandList: [],
      // 状态
      options: [],
      // 弹出层标题
      title: '',
      title1: '',
      // 是否显示弹出层
      open: false,
      dialogVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {
        attachImage: null,
        content: null,
        createId: null,
        createTime: null,
        delFlag: null,
        employeeId: null,
        employeeName: null,
        employeePhone: null,
        feedbackChannel: null,
        feedbackTime: null,
        id: null,
        remarks: null,
        updateId: null,
        updateTime: null,
        version: null
      },
      form1: {
        orderMoney: null
      },
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询意见反馈列表 */
    getList() {
      getOpinion(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
        const { total, records } = res.data
        this.total = total
        this.equWristbandList = records
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        attachImage: undefined,
        content: undefined,
        createId: undefined,
        createTime: undefined,
        delFlag: undefined,
        employeeId: undefined,
        employeeName: undefined,
        employeePhone: undefined,
        feedbackChannel: undefined,
        feedbackTime: undefined,
        id: undefined,
        remarks: undefined,
        updateId: undefined,
        updateTime: undefined,
        version: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.handleQuery()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getNameId(row)
      this.title = '查看反馈信息'
      this.open = true
    },
    /** 评价内容**/
    getNameId(row) {
      getByOpinionId(row.id).then(res => {
        this.form = res.data
        const { feedbackChannel } = res.data
        this.form.feedbackChannel = feedbackChannel === '1' ? '企业端' : '员工端'
      })
    },
    /** 订单信息 **/
    handleStatusChange(row) {
      getCompanyOrderInfo(row.employeeId).then(res => {
        const { order } = res.data
        this.form1.orderMoney = order.orderMoney
      })
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.open = false
        }
      })
    },
    /** 处理图片 **/
    getImg(val) {
      const arr = [null, undefined, '']
      if (arr.includes(val)) {
        return []
      }
      return val.split(',')
    },
    /** 查看图片 **/
    getImgValue(row) {
      this.dialogImageUrl = row
      this.dialogVisible = true
      this.title1 = '查看照片'
    }
  }
}
</script>
